using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace DAL
{
    class DataAccessObject
    {
        private static MyConnection myConnection;
        private static string serverName;
        private static string databaseName;
        private static string userName;
        private static string password;
        private static string infoPath = "DatabaseProperties.xml";

        public DataAccessObject()
        {

        }

        static DataAccessObject()
        {
            LoadConnectionInfo();
        }

        public static MyConnection GetDAL()
        {
            string connectionString = "Data Source=" + serverName + ";Initial Catalog=" + databaseName + ";User ID=" + userName + ";Password=" + password;
            connectionString += ";Max Pool Size=100;Min Pool Size=5";
            myConnection = new MyConnection(connectionString);
            return myConnection;
        }

        private static void LoadConnectionInfo()
        {
            XmlDocument docXML = new XmlDocument();
            docXML.Load(infoPath);
            serverName = docXML.SelectSingleNode("//ServerName").InnerText;
            databaseName = docXML.SelectSingleNode("//DatabaseName").InnerText;
            userName = docXML.SelectSingleNode("//Username").InnerText;
            password = docXML.SelectSingleNode("//Password").InnerText;
        }
    }//end DataAccessObject
}


